﻿using System;
using System.Data;
using System.Collections;
using System.Collections.Specialized;

using Common;

namespace com.globalwave.website
{
    public partial class BoardPage : Common.BasePage
    {
        public BoardPage()
            : base()
        {
            entityName = "Board";
        }


        public void list()
        {

            NameValueCollection criterion = getCriterion();

            DataSet ds = BoardService.getInstance().query(criterion, pageIndex, pageSize, null);

            renderListXML(ds);
        }

        public void create()
        {
            NameValueCollection board = getBoard();

            int board_id =
                BoardService.getInstance().create(board);

            board.Set("board_id", board_id.ToString());

            renderSuccessCreateMessage(board);

        }

        public void update()
        {

            NameValueCollection board = getBoard();

            BoardService.getInstance().update(board);


            renderSuccessUpdateMessage(board);

        }

        public void delete()
        {
            string[] board_ids = this.getBoard_ids();

            if (board_ids == null)
            {
                BoardService.getInstance().delete(getBoard());
            }
            else
            {
                BoardService.getInstance().deleteAll(board_ids);
            }

            renderSuccessDeleteMessage();

        }

        /*
        public void possessedByUser()
        {
            DataSet ds = BoardService.getInstance().possessedByUser(Request.Params.Get("user_id"));

            renderXML(ds);


        }

        public void possessedByOrganization()
        {
            DataSet ds = BoardService.getInstance().possessedByOrganization(Request.Params.Get("organization_id"));

            renderListXML(ds);

        }
        */

        private NameValueCollection getCriterion()
        {

            return U.filter(Request.Params, "boardCriterion")[0];
        }

        private NameValueCollection getBoard()
        {

            NameValueCollection board = U.filter(Request.Params, "board")[0];
            if ("".Equals(board.Get("pro_board_id")))
            {
                board.Set("pro_board_id", null);
            }
            return board;
        }

        private string[] getBoard_ids()
        {
            return Request.Params.GetValues("board_ids");
        }
    }
}
